{
  class Queue<T> {
    private dataStore: T[] = [];
    get length(): number {
      return this.dataStore.length;
    }
    enqueus(element: T) {
      this.dataStore.push(element);
    }
    dequeus(): T | undefined {
      return this.dataStore.shift();
    }
    front(): T {
      return this.dataStore[0];
    }
    back(): T {
      return this.dataStore[this.length - 1];
    }
    toString() {
      return this.dataStore.map((item) => item).join("\n");
    }
    clear() {
      this.dataStore.length = 0;
    }
    isEmpty() {
      return this.length === 0;
    }
  }

  // let que = new Queue<String>();
  // que.enqueus("Jimmy");
  // que.enqueus("xuexue");
  // que.enqueus("Jack");
  // que.enqueus("Henry");
  // console.log(que.front());
  // console.log(que.back());
  // console.log(que.dequeus());
  // console.log(que.length);
  // console.log(que.toString());
  // console.log(que.clear());
  // console.log(que.isEmpty());

  let queues: Queue<Number>[] = [];
  for (var i = 0; i < 10; ++i) {
    queues[i] = new Queue<Number>();
  }
  let nums = [];
  for (var i = 0; i < 10; ++i) {
    nums[i] = Math.floor(Math.floor(Math.random() * 101));
  }

  console.log("BEFORE", nums);

  const distribute = (
    nums: number[],
    queues: Queue<Number>[],
    n: number,
    digit: number
  ) => {
    for (let i = 0; i < n; i++) {
      if (digit == 1) {
        queues[nums[i] % 10].enqueus(nums[i]);
      } else {
        queues[Math.floor(nums[i] / 10)].enqueus(nums[i]);
      }
    }
  };

  const collect = (queuss: Queue<Number>[], nums: number[]) => {
    let i = 0;
    for (let digit = 0; digit < 10; digit++) {
      while (!queuss[digit].isEmpty()) {
        nums[i++] = queuss[digit].dequeus() as number;
      }
    }
  };
  // 第一次收集
  distribute(nums, queues, 10, 1);
  collect(queues, nums);
  // 第二次收集
  distribute(nums, queues, 10, 10);
  collect(queues, nums);
  console.log("NOW", nums);
}
